package com.ruoyi.register.utils;


import com.ruoyi.register.entily.User;
import org.apache.http.HttpResponse;


import java.util.HashMap;
import java.util.Map;

public class AllAuthentication {


    /**
     * 身份证认证
     */
    public  static Boolean IdCardAuthentication(User user){
        String host = "https://sfzsmyxb.market.alicloudapi.com";
        String path = "/get/idcard/checkV3";
        String method = "GET";
        String appcode = "a4181b52a8764114a0549aefb20a19e0";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("idcard",user.getIdcard());
        querys.put("name", user.getUname());
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            System.out.println(response.toString());
            return  true;
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
            return  false;
    }


    /**
     * 银行卡认证
     */
    public  static  boolean CardAuthentication(String cardNumber, String idNumber, String realName){
        String host = "https://dfbank3.market.alicloudapi.com";
        String path = "/verify_id_name_bankcard";
        String method = "POST";
        String appcode = "a4181b52a8764114a0549aefb20a19e0";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("card_number", cardNumber);
        bodys.put("id_number", idNumber);
        bodys.put("name", realName);


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            return true;
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


}
